import numpy as np
import os

def bin_to_txt_float16(bin_path, txt_path):
    data = np.fromfile(bin_path, dtype=np.float16)
    with open(txt_path, 'w') as f:
        for item in data:
            f.write(f"{item:.6f}\n")  # 保留6位小数，可以改成其他位数
    print(f"[INFO] Converted {bin_path} to {txt_path} (float16).")

def bin_to_txt_bool(bin_path, txt_path):
    data = np.fromfile(bin_path, dtype=np.bool_)
    with open(txt_path, 'w') as f:
        for item in data:
            f.write(f"{int(item)}\n")  # 写成 0 或 1
    print(f"[INFO] Converted {bin_path} to {txt_path} (bool).")

if __name__ == "__main__":
    os.makedirs("txt_output", exist_ok=True)
    bin_to_txt_float16("./input/input_x1.bin", "./txt_output/input_x1.txt")
    bin_to_txt_float16("./input/input_x2.bin", "./txt_output/input_x2.txt")
    bin_to_txt_bool("./output/golden.bin", "./txt_output/golden.txt")
    bin_to_txt_bool("./output/output_y.bin", "./txt_output/output_y.txt")
